﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Microsoft.Xna.Framework;

namespace Zombie_Demo.User_Interface
{
     [Serializable]
     [XmlRoot("BackgroundRect")]
     public class BackgroundRectangle : Element
     {
         /// <summary>
         /// Color variable
         /// </summary>
          protected Color color;

         /// <summary>
         /// Color of the rect
         /// </summary>
          public Color Color { get { return this.color; } set { this.color = value; } }

         /// <summary>
         /// Make a new starndard rectangle, at (0,0) and 10x10
         /// </summary>
          public BackgroundRectangle()
               : base()
          {
               bounds = new Rectangle(0, 0, 10, 10);
               color = Color.Black;
          }

         /// <summary>
         /// Make a new rectangle
         /// </summary>
         /// <param name="rect">The supplied rectangle</param>
          public BackgroundRectangle(Rectangle rect)
               : base()
          {
               this.bounds = rect;
               color = Color.Black;
          }

         /// <summary>
         /// Make a new rectangle
         /// </summary>
         /// <param name="rect">The supplied rectangle</param>
         /// <param name="color">The color of the rectangle</param>
          public BackgroundRectangle(Rectangle rect, Color color)
               : base()
          {
               this.bounds = rect;
               this.color = color;
          }
         
         /// <summary>
         /// Make a new rectangle
         /// </summary>
         /// <param name="rect">The supplied rectangle</param>
         /// <param name="color">The color of the rectangle</param>
         /// <param name="name">Human readable string name</param>
          public BackgroundRectangle(Rectangle rect, Color color, string name)
              : base()
          {
              this.bounds = rect;
              this.color = color;
              this.name = Parent.Name + name;
          }

          /// <summary>
          /// Make a new rectangle
          /// </summary>
          /// <param name="rect">The supplied rectangle</param>
          /// <param name="color">The color of the rectangle</param>
         /// <param name="parent">Set this as a child to the supplied parent</param>
          public BackgroundRectangle(Rectangle rect, Color color, Element parent)
               : base(parent)
          {
               this.bounds = rect;
               this.color = color;
          }

         /// <summary>
         /// Construct a new rectangle
         /// </summary>
         /// <param name="position">X and Y position of the upper left corner</param>
         /// <param name="width">Width in pixel units</param>
         /// <param name="height">Height in pixel units</param>
         /// <param name="color">Color of the supplied rectangle</param>
         /// <param name="parent">Set this as a child to the supplied parent</param>
          public BackgroundRectangle(Vector2 position, int width, int height, Color color, Element parent)
               : base(parent, position)
          {
               this.bounds = new Rectangle((int)position.X, (int)position.Y, width, height);
               this.color = color;
          }

         /// <summary>
         /// Initialize the bounds, and name if there is a parent
         /// </summary>
          public override void Load()
          {
              base.Load();
              this.bounds = new Rectangle((int)Position.X, (int)Position.Y, bounds.Width, bounds.Height);
              if (this.Parent != null)
              {
                  if (this.name != null)
                      this.name = Parent.Name + this.name;
                  else
                      this.name = Parent.Name + "BGRect";
              }
          }

         /// <summary>
         /// Standard Draw function
         /// </summary>
         /// <param name="gameTime">GameTime object</param>
         /// <param name="spriteBatch">SpriteBatch to draw on</param>
          public override void Draw(GameTime gameTime, Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
          {
               spriteBatch.Draw(Utilities.ContentLibrary.GetTexture("basicPixel"), bounds, color);
               base.Draw(gameTime, spriteBatch);
          }
     }
}
